<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

class Notice extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
    }

  //在线课堂首页
    public function index()
    {
        $this->assign("title", "平台公告");
        $this->assign("foot_nav_index", "2");
        
        //分类

        return $this->view->fetch();
    }

    //文章列表- 商学院
    public function list()
    {
        $category_id = input("cid", 0);
        $keyword = input("keyword", '');
        $page = input('page', 1);
        $where = [];
//        if($category_id==0){
//            $cateIds = Db::name('article_category')->where(['pid'=>5])->column('id');
//            $where['category_id'] = ['in',$cateIds];
//        }else{
//            $where['category_id'] = $category_id;
//        }
        $where['category_id'] = 5;
        if($keyword!=''){
            $where['title'] = ['like',"%{$keyword}%"];
        }
        $list = db("article")->where($where)->page($page, 10)->select();
        foreach ($list as $key => $val) {
            $list[$key]["createtime_format"] = date("Y-m-d H:i:s", $val["createtime"]);
        }

        return $this->success('', '', $list);
    }

    //文章详情页
    public function detail()
    {
        $id = input("id", 0);
        $article = db("article")->where("id", $id)->find();
        // exit(print_r($article));
        if($article){
            db("article")->where("id", $id)->setInc("read_count",1);
            $article["createtime_format"]=date("Y年m月d日 H:i", $article["createtime"]);
        }
        $this->assign("title", $article['title']);
        $this->assign("article", $article);
        $this->assign("foot_nav_index", "2");

        return $this->view->fetch();
    }
}
 